﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace myking
{
    /// <summary>
    /// 记录历史代码
    /// </summary>
    public static class HistoryScript
    {

        #region api申明
        [DllImport("user32.dll", EntryPoint = "GetCursorPos")]
        public static extern bool GetCursorPos(ref Point lpPoint);

        [DllImport("user32.dll", EntryPoint = "GetWindowText")]
        public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);

        [DllImport("user32.dll", EntryPoint = "SendMessage")]
        public static extern int SendMessage(IntPtr hwnd, int wMsg, string wParam, string lParam);

        [DllImport("user32.dll", EntryPoint = "SendMessage")]
        public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

        [DllImport("user32.dll", EntryPoint = "SendMessage")]
        public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, System.Text.StringBuilder lParam);

        [DllImport("User32.dll", EntryPoint = "PostMessage")]
        private static extern int PostMessage(IntPtr hWnd, int Msg, uint wParam, int t);

        [DllImport("user32.dll", EntryPoint = "mouse_event")]
        public static extern void mouse_event(int wMsg, int pointx, int pointy, int pointh, int lParam);

        [DllImport("user32.dll")]
        private static extern int GetWindowRect(IntPtr hwnd, out  Rect lpRect);

        [DllImport("user32")]
        public static extern int GetSystemMetrics(int nIndex);

        [DllImport("user32.dll", CharSet = CharSet.Ansi)]
        public static extern int ShowWindow(IntPtr hwnd, int nShowCmd);

        [DllImport("kernel32.dll", ExactSpelling = true)]
        internal static extern IntPtr GetCurrentProcess();

        //提升权限新添加
        [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
        internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);

        [DllImport("advapi32.dll", SetLastError = true)]
        internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);

        [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
        internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
         ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);

        [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
        internal static extern bool ExitWindowsEx(int flg, int rea);
        //end

        //读取进程内存的函数
        [DllImport("kernel32.dll ")]
        static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, out int lpBuffer, int nSize, out int lpNumberOfBytesRead);

        //通过GetWindowThreadProcessId读取查找窗体句柄进程的PID值
        [DllImport("user32.dll")]
        private static extern int GetWindowThreadProcessId(IntPtr id, out int pid);

        //得到目标进程句柄的函数
        [DllImport("kernel32.dll")]
        public static extern int OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);

        #region sendinput的api相关定义
        [DllImport("user32.dll")]
        public static extern UInt32 SendInput(UInt32 nInputs, Input[] pInputs, int cbSize);

        [StructLayout(LayoutKind.Sequential)]
        public struct MouseInput
        {
            public Int32 dx;
            public Int32 dy;
            public Int32 Mousedata;
            public Int32 dwFlag;
            public Int32 time;
            public IntPtr dwExtraInfo;
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct tagKEYBDINPUT
        {
            Int16 wVk;
            Int16 wScan;
            Int32 dwFlags;
            Int32 time;
            IntPtr dwExtraInfo;
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct tagHARDWAREINPUT
        {
            Int32 uMsg;
            Int16 wParamL;
            Int16 wParamH;
        }

        [StructLayout(LayoutKind.Explicit)]
        public struct Input
        {
            [FieldOffset(0)]
            public Int32 type;
            [FieldOffset(4)]
            public MouseInput mi;
            [FieldOffset(4)]
            public tagKEYBDINPUT ki;
            [FieldOffset(4)]
            public tagHARDWAREINPUT hi;
        }

        const int MouseEvent_Absolute = 0x8000;
        const int MouserEvent_Hwheel = 0x01000;
        const int MouseEvent_Move = 0x0001;
        const int MouseEvent_Move_noCoalesce = 0x2000;
        const int MouseEvent_LeftDown = 0x0002;
        const int MouseEvent_LeftUp = 0x0004;
        const int MouseEvent_MiddleDown = 0x0020;
        const int MouseEvent_MiddleUp = 0x0040;
        const int MouseEvent_RightDown = 0x0008;
        const int MouseEvent_RightUp = 0x0010;
        const int MouseEvent_Wheel = 0x0800;
        const int MousseEvent_XUp = 0x0100;
        const int MousseEvent_XDown = 0x0080;

        #endregion


        #endregion

        #region 常量声明
        const int MOUSEEVENTF_MOVE = 0x0001;     // 移动鼠标           (十):1
        const int MOUSEEVENTF_LEFTDOWN = 0x0002; //模仿鼠标左键按下    (十):2
        const int MOUSEEVENTF_LEFTUP = 0x0004; //模仿鼠标左键抬起    (十):4
        const int MOUSEEVENTF_RIGHTDOWN = 0x0008; //模仿鼠标右键按下    (十):8
        const int MOUSEEVENTF_RIGHTUP = 0x0010; //模仿鼠标右键抬起    (十):16
        const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;// 模仿鼠标中键按下    (十):32
        const int MOUSEEVENTF_MIDDLEUP = 0x0040;// 模仿鼠标中键抬起    (十):64
        const int MOUSEEVENTF_ABSOLUTE = 0x8000; //标示是否采取绝对坐标    (十):32768

        const int SM_CXSCREEN = 0;      //屏幕宽度
        const int SM_CYSCREEN = 1;      //屏幕高度

        const int WM_KEYDOWN = 0x100; //按键按下
        const int WM_KEYUP = 0x101; //按键抬起
        const int WM_CHAR = 0x0102;

        const int SW_HIDE = 0;
        const int SW_SHOWNORMAL = 1;
        const int SW_SHOWMINIMIZED = 2;
        const int SW_SHOWMAXIMIZED = 3;
        const int SW_SHOW = 6;

        const int WM_SETTEXT = 0xC;
        const int WM_GETTEXT = 0xD;

        internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
        internal const int TOKEN_QUERY = 0x00000008;
        internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
        internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
        internal const int EWX_LOGOFF = 0x00000000;
        internal const int EWX_SHUTDOWN = 0x00000001;
        internal const int EWX_REBOOT = 0x00000002;
        internal const int EWX_FORCE = 0x00000004;
        internal const int EWX_POWEROFF = 0x00000008;
        internal const int EWX_FORCEIFHUNG = 0x00000010;

        const int PROCESS_ALL_ACCESS = 0x1F0FFF;
        const int PROCESS_VM_READ = 0x0010;
        const int PROCESS_VM_WRITE = 0x0020;

        #endregion

        #region 变量
        private static double temptime { get; set; }

        public static double delaytime { get; set; }

        public static string businesstypeName { get; set; }

        public static IntPtr programhWnd { get; set; }

        public static int programhwnd { get; set; }

        public static string titlename { get; set; }

        public static int keydown { get; set; }

        /// <summary>
        /// 所有区块命令合集
        /// </summary>
        public static Dictionary<string, ArrayList> cmdarraylist { get; set; }

        /// <summary>
        /// 变量数组
        /// </summary>
        public static Dictionary<string, ArrayList> varArrayList { get; set; }

        /// <summary>
        /// 变量下标数组
        /// </summary>
        public static Dictionary<string, int> varNumberList { get; set; }

        /// <summary>
        /// 游戏内部变量
        /// </summary>
        public static Dictionary<string, int> gamevalue { get; set; }

        private struct Rect
        {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;
        }

        ///// <summary>
        ///// 当前mp
        ///// </summary>
        //public static int m { get; set; }

        ///// <summary>
        ///// 最大MP
        ///// </summary>
        //public static int M { get; set; }

        ///// <summary>
        ///// 当前hp
        ///// </summary>
        //public static int h { get; set; }

        ///// <summary>
        ///// 最大hp
        ///// </summary>
        //public static int H { get; set; }

        internal struct TokPriv1Luid
        {
            public int Count;
            public long Luid;
            public int Attr;
        }

        #endregion

        /// <summary>
        /// 系统延时(进程不停止)
        /// </summary>
        private static void delay(double tol)//tol=20s
        {
            DateTime orinowtime = DateTime.Now;//记录延时开始的系统当前时间
            while (orinowtime.AddSeconds(tol).CompareTo(DateTime.Now) >= 0)//延时20s
                temptime = tol;
        }

        ///// <summary>
        ///// 系统延时(进程停止)
        ///// </summary>
        //private static void truedelay(double tol)//tol=20s
        //{
        //    int waitsecond = (int)(tol * 1000);
        //    Thread.Sleep(waitsecond);
        //}

        ///// <summary>
        ///// 发送单次命令
        ///// </summary>
        ///// <param name="instr"></param>
        //private static void SendOnceMessage(string instr)
        //{
        //    uint vk_f;
        //    char c;
        //    int n;
        //    double waittime;

        //    //调用子程序
        //    if (instr.Length > 4)
        //    {
        //        if (instr.Substring(0, 4) == "call")
        //        {
        //            LoopScript(cmdarraylist[instr.Substring(5, instr.Length - 5)], dm);
        //            return;
        //        }
        //    }

        //    //等待时间
        //    if (instr.Length > 4)
        //    {
        //        if (instr.Substring(0, 4) == "wait")
        //        {
        //            waittime = Convert.ToDouble(instr.Substring(4, instr.Length - 4));
        //            truedelay(waittime);
        //            return;
        //        }
        //    }

        //    int pos = instr.IndexOf("::", 0);

        //    string commandtmp = string.Empty;
        //    //命令格式
        //    if (pos > 0)
        //    {
        //        delaytime = Convert.ToDouble(instr.Substring(0, pos));
        //        commandtmp = instr.Substring(pos + 2, instr.Length - pos - 2);

        //        //替换循环变量
        //        foreach (string _key in varArrayList.Keys)
        //        {
        //            //on %va
        //            int findpos = commandtmp.IndexOf("%v" + _key, 0);
        //            if (findpos > 0)
        //            {
        //                commandtmp = commandtmp.Replace("%v" + _key, varArrayList[_key][varNumberList[_key]].ToString());
        //                AddvarNumber(_key, varArrayList[_key]);
        //                break;
        //            }
        //        }
        //    }
        //    else
        //    {
        //        return;
        //    }

        //    //int ret = dm.SendString((int)programhWnd, commandtmp); //调用动态库发送

        //    for (int i = 0; i < commandtmp.Length; i++)
        //    {
        //        c = Convert.ToChar(commandtmp.Substring(i, 1));
        //        n = Convert.ToInt32(c);
        //        vk_f = (uint)n;
        //        PostMessage(programhWnd, WM_CHAR, vk_f, 0);
        //    }
        //    vk_f = (uint)13;
        //    PostMessage(programhWnd, WM_KEYDOWN, vk_f, 0);
        //    truedelay(delaytime);
        //    truedelay(0.2);
        //    //Log.WriteLog("循环记录", commandtmp + ",等待时间" + delaytime.ToString(), "循环记录");
        //    Log.WriteLog("循环记录", commandtmp, "循环记录");
        //}

        ///// <summary>
        ///// 修改标题
        ///// </summary>
        //public static void ChangeTitle()
        //{
        //    if (string.IsNullOrEmpty(titlename))
        //    {
        //        //
        //    }
        //    else
        //    {
        //        SendMessage(programhWnd, WM_SETTEXT, titlename, titlename);
        //    }
        //}

        ///// <summary>
        ///// 发送命令
        ///// </summary>
        //public static void MySendMessage()
        //{
        //    InitGameValue();
        //    CDmSoft dm = new CDmSoft();
        //    dm.BindWindow((int)programhWnd, "dx3", "windows3", "normal", 0); //绑定窗口
        //    ChangeTitle();
        //    while (businesstypeName == "Y")
        //    {
        //        LoopScript(cmdarraylist["begin"], dm);
        //    }
        //    dm.Dispose();
        //    dm = null;
        //}

        ///// <summary>
        ///// 临时发送按键
        ///// </summary>
        //public static void MySendtemp()
        //{
        //    //uint vk_f;
        //    //while (businesstypeName == "Y")
        //    //{
        //    //    vk_f = (uint)keydown;
        //    //    PostMessage(programhWnd, WM_CHAR, vk_f, 0);
        //    //    vk_f = (uint)13;
        //    //    PostMessage((IntPtr)programhwnd, WM_KEYDOWN, vk_f, 0);
        //    //    truedelay(delaytime);
        //    //    truedelay(0.2);
        //    //}
        //    CDmSoft dm = new CDmSoft();
        //    int result = 0;
        //    int hp = dm.ReadInt(programhwnd, "092D1772", 1);
        //    //result = dm.BindWindow(programhwnd, "dx", "windows", "dx", 0); //绑定窗口
        //    //result = dm.BindWindow(programhwnd, "dx", "windows", "windows", 0);
        //    result = dm.BindWindow(programhwnd, "normal", "normal", "normal", 0);
        //    //truedelay(0.3);
        //    //dm.SetWindowState(programhwnd, 1);
        //    //truedelay(0.3);
        //    while (businesstypeName == "Y")
        //    {
        //        truedelay(0.3);
        //        dm.SendString(programhwnd, "tie");
        //        truedelay(0.3);
        //        //dm.KeyPressChar("enter");
        //        truedelay(0.3);
        //        truedelay(0.3);
        //        result = dm.KeyPressChar("F1");
        //        truedelay(delaytime);
        //        //dm.LeftClick();
        //        //result = dm.KeyDown(keydown);
        //        //truedelay(0.3);
        //        //result = dm.KeyUp(keydown);
        //        truedelay(delaytime);
        //    }
        //    dm.Dispose();
        //    dm = null;
        //}


        ///// <summary>
        ///// 循环获取命令内容
        ///// </summary>
        ///// <param name="inlist"></param>
        //private static void LoopScript(ArrayList inlist)
        //{
        //    int looptimes = 0;
        //    int endlooptimes = 0;
        //    int loopsecond = 0;
        //    Boolean loopflag = false;
        //    Boolean firstloop = false;
        //    ArrayList loopmsg = new ArrayList();
        //    Boolean ifflag = false;
        //    Boolean firstif = false;
        //    Boolean ifend = false;
        //    Boolean ifResult = false;
        //    int checkvalue = 0;
        //    int iftimes = 0;


        //    //将脚本分区块
        //    Dictionary<string, ArrayList> scriptDict = new Dictionary<string, ArrayList>();

        //    foreach (var item in inlist)
        //    {
        //        if (businesstypeName != "Y")
        //        {
        //            return;
        //        }
        //        if (item == null)
        //        {
        //            continue;
        //        }
        //        string tmpstr = item.ToString();

        //        //添加if开始判断
        //        if ((tmpstr.Length > 2) && (tmpstr.Substring(0, 2) == "if"))
        //        {
        //            ifflag = true;
        //            //if (!firstif)
        //            //{
        //            firstif = true;
        //            //获取if的变量 if (%m > 200)
        //            string ifvar = string.Empty;
        //            ifvar = tmpstr.Substring(5, 1);
        //            string ifSymbol = tmpstr.Substring(7, 1);
        //            int ifvalue = Convert.ToInt32(tmpstr.Substring(9, tmpstr.Length - 10));

        //            checkvalue = gamevalue[ifvar];

        //            switch (ifSymbol)
        //            {
        //                case "="://注释
        //                    if (checkvalue == ifvalue)
        //                    {
        //                        ifResult = true;
        //                    }
        //                    break;
        //                case ">"://注释
        //                    if (checkvalue > ifvalue)
        //                    {
        //                        ifResult = true;
        //                    }
        //                    break;
        //                case "<"://注释
        //                    if (checkvalue < ifvalue)
        //                    {
        //                        ifResult = true;
        //                    }
        //                    break;
        //                case "~"://注释
        //                    if (ifvalue != checkvalue)
        //                    {
        //                        ifResult = true;
        //                    }
        //                    break;
        //                default:
        //                    ifResult = false;
        //                    break;
        //            }
        //            if (ifResult)
        //            {

        //            }
        //            //}
        //            //else
        //            //{

        //            //}
        //            iftimes++;
        //            continue;
        //        }

        //        if ((tmpstr.Length == 5) && (tmpstr.Substring(0, 5) == "endif"))
        //        {
        //            ifResult = false;
        //            ifflag = false;
        //            continue;

        //        }

        //        if (ifflag && !ifResult)
        //        {
        //            continue;//if中并且条件失败
        //        }

        //        if ((tmpstr.Length > 4) && (tmpstr.Substring(0, 4) == "loop"))
        //        {
        //            loopflag = true;
        //            if (!firstloop)
        //            {
        //                firstloop = true;
        //                loopsecond = Convert.ToInt32(tmpstr.Substring(4, tmpstr.Length - 4));
        //            }
        //            else
        //            {
        //                loopmsg.Add(tmpstr);
        //            }
        //            looptimes++;
        //            continue;
        //        }

        //        //支持foreach开始
        //        if ((tmpstr.Length > 7) && (tmpstr.Substring(0, 7) == "foreach"))
        //        {
        //            loopflag = true;
        //            if (!firstloop)
        //            {
        //                firstloop = true;
        //                string key = tmpstr.Substring(7, tmpstr.Length - 7).Trim();

        //                foreach (string _key in varArrayList.Keys)
        //                {
        //                    if (key == _key.ToString())
        //                    {
        //                        loopsecond = varArrayList[key].Count;
        //                        break;
        //                    }
        //                }
        //                if (loopsecond <= 0)
        //                {
        //                    loopsecond = 1;
        //                }
        //            }
        //            else
        //            {
        //                loopmsg.Add(tmpstr);
        //            }
        //            looptimes++;
        //            continue;
        //        }

        //        if ((tmpstr.Length == 7) && (tmpstr.Substring(0, 7) == "endloop"))
        //        {
        //            endlooptimes++;
        //            if (looptimes == endlooptimes)
        //            {

        //                //循环完成
        //                loopflag = false;
        //                firstloop = false;
        //                for (int i = 0; i < loopsecond; i++)
        //                {
        //                    LoopScript(loopmsg, dm);
        //                }
        //                loopmsg.Clear();
        //            }
        //            else
        //            {
        //                loopmsg.Add(tmpstr);
        //            }
        //            continue;
        //        }

        //        //支持foreach结束
        //        if ((tmpstr.Length == 4) && (tmpstr == "loop"))
        //        {
        //            endlooptimes++;
        //            if (looptimes == endlooptimes)
        //            {

        //                //循环完成
        //                loopflag = false;
        //                firstloop = false;
        //                for (int i = 0; i < loopsecond; i++)
        //                {
        //                    LoopScript(loopmsg, dm);
        //                }
        //                loopmsg.Clear();
        //            }
        //            else
        //            {
        //                loopmsg.Add(tmpstr);
        //            }
        //            continue;
        //        }

        //        if (loopflag)
        //        {
        //            loopmsg.Add(tmpstr);
        //            continue;
        //        }

        //        SendOnceMessage(tmpstr, dm);

        //    }


        //}

        ///// <summary>
        ///// 前台鼠标移动
        ///// </summary>
        //public static void movemouse()
        //{
        //    int x = 0;
        //    int y = 0;

        //    // 获取当前鼠标坐标
        //    delay(delaytime);
        //    Point defpoint = new Point();
        //    GetCursorPos(ref defpoint);
        //    x = defpoint.X;
        //    y = defpoint.Y;

        //    //换算到event点
        //    int mx = x * 65535 / GetSystemMetrics(SM_CXSCREEN);
        //    int my = y * 65535 / GetSystemMetrics(SM_CYSCREEN);
        //    mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, mx, my, 0, 0);

        //    //移动鼠标,右键点击
        //    mouse_event(0x0008, 0, 0, 0, 0);//右键down 
        //    delay(0.1);//按下与松开之间需要暂停
        //    mouse_event(0x0010, 0, 0, 0, 0);//右键up

        //}

        ///// <summary>
        ///// 窗口显示
        ///// </summary>
        //public static void setwindowShow()
        //{
        //    ShowWindow(programhWnd, SW_SHOW);

        //}

        ///// <summary>
        ///// 窗口隐藏
        ///// </summary>
        //public static void setwindowHide()
        //{
        //    //SW_HIDE
        //    ShowWindow(programhWnd, SW_HIDE);

        //}

        ///// <summary>
        ///// 先获取脚本中所有的key值
        ///// </summary>
        //private static int getCommandKey(ArrayList inlist, out  ArrayList outKey, out string errormsg)
        //{
        //    errormsg = string.Empty;
        //    outKey = new ArrayList();
        //    Boolean beginflag = false;
        //    Boolean keyfind = false;
        //    string key = string.Empty; //分类
        //    foreach (var item in inlist)
        //    {
        //        if (item == null)
        //        {
        //            continue;
        //        }
        //        string commanLine = item.ToString().Trim();
        //        if (string.IsNullOrEmpty(commanLine))
        //        {
        //            continue;
        //        }

        //        switch (commanLine.Substring(0, 1))
        //        {
        //            case "#"://注释
        //            case "/"://注释
        //            case "-"://注释
        //                continue;
        //            default:
        //                break;
        //        }

        //        //判断区块标志
        //        if (commanLine.Length > 7)
        //        {
        //            if (commanLine.Substring(0, 6) == "%scene")
        //            {
        //                key = Convert.ToString(commanLine.Substring(7, commanLine.Length - 7));
        //                keyfind = false;
        //                if (key == "begin")
        //                {
        //                    beginflag = true;
        //                }
        //                foreach (var itemdetail in outKey)
        //                {
        //                    if (itemdetail == null)
        //                    {
        //                        continue;
        //                    }
        //                    string tempkey = itemdetail.ToString().Trim();
        //                    if (tempkey == key)
        //                    {
        //                        keyfind = true;
        //                    }
        //                }
        //                if (!keyfind)
        //                {
        //                    outKey.Add(key);
        //                }
        //            }
        //        }
        //    }

        //    if (!beginflag)
        //    {
        //        errormsg = "未找到代码开始标志!";
        //        return -1;
        //    }

        //    return 0;
        //}

        ///// <summary>
        ///// 获取脚本中变量的key值
        ///// </summary>
        //private static int getVarKey(ArrayList inlist, out  ArrayList outKey, out string errormsg)
        //{
        //    errormsg = string.Empty;
        //    outKey = new ArrayList();
        //    Boolean keyfind = false;
        //    string key = string.Empty; //分类
        //    foreach (var item in inlist)
        //    {
        //        if (item == null)
        //        {
        //            continue;
        //        }
        //        string commanLine = item.ToString().Trim();
        //        if (string.IsNullOrEmpty(commanLine))
        //        {
        //            continue;
        //        }

        //        switch (commanLine.Substring(0, 1))
        //        {
        //            case "#"://注释
        //            case "/"://注释
        //            case "-"://注释
        //                continue;
        //            default:
        //                break;
        //        }

        //        //判断区块标志
        //        if (commanLine.Length > 10)
        //        {
        //            if (commanLine.Substring(0, 9) == "%variable")
        //            {
        //                key = Convert.ToString(commanLine.Substring(10, commanLine.Length - 10));
        //                keyfind = false;
        //                foreach (var itemdetail in outKey)
        //                {
        //                    if (itemdetail == null)
        //                    {
        //                        continue;
        //                    }
        //                    string tempkey = itemdetail.ToString().Trim();
        //                    if (tempkey == key)
        //                    {
        //                        keyfind = true;
        //                    }
        //                }
        //                if (!keyfind)
        //                {
        //                    outKey.Add(key);
        //                }
        //            }
        //        }
        //    }
        //    return 0;
        //}


        ///// <summary>
        ///// 获取key值对应的value
        ///// </summary>
        //private static ArrayList spiltCommandList(string key, ArrayList inlist)
        //{
        //    ArrayList value = new ArrayList();
        //    string listkey = string.Empty;

        //    foreach (var item in inlist)
        //    {
        //        if (item == null)
        //        {
        //            continue;
        //        }
        //        string commanLine = item.ToString().Trim();
        //        //判断区块标志
        //        if (commanLine.Length > 7)
        //        {
        //            if (commanLine.Substring(0, 6) == "%scene")
        //            {
        //                listkey = Convert.ToString(commanLine.Substring(7, commanLine.Length - 7));
        //                continue;
        //            }
        //        }
        //        if (listkey == key)
        //        {
        //            value.Add(commanLine);
        //        }
        //    }
        //    return value;
        //}

        ///// <summary>
        ///// 获取变量key对应的value
        ///// </summary>
        //private static ArrayList spiltVarList(string key, ArrayList inlist)
        //{
        //    ArrayList value = new ArrayList();
        //    string listkey = string.Empty;

        //    foreach (var item in inlist)
        //    {
        //        if (item == null)
        //        {
        //            continue;
        //        }
        //        string commanLine = item.ToString().Trim();

        //        //变量快必须在区块前
        //        if (commanLine.Length > 7)
        //        {
        //            if (commanLine.Substring(0, 6) == "%scene")
        //            {
        //                return value;
        //            }
        //        }

        //        //判断区块标志
        //        if (commanLine.Length > 9)
        //        {
        //            if (commanLine.Substring(0, 9) == "%variable")
        //            {
        //                listkey = Convert.ToString(commanLine.Substring(10, commanLine.Length - 10));
        //                continue;
        //            }
        //        }
        //        if (listkey == key)
        //        {
        //            value.Add(commanLine);
        //        }
        //    }
        //    return value;
        //}


        ///// <summary>
        ///// 获取指定路径脚本的代码
        ///// </summary>
        //public static int GetScript(string scriptpathname, out string errmsg)
        //{
        //    errmsg = string.Empty;
        //    if (string.IsNullOrEmpty(scriptpathname))
        //    {
        //        errmsg = "代码路径为空!";
        //        return -1;
        //    }

        //    StreamReader objReader = new StreamReader(scriptpathname);
        //    string sLine = "";
        //    ArrayList LineList = new ArrayList();
        //    while (sLine != null)
        //    {
        //        sLine = objReader.ReadLine();
        //        if (string.IsNullOrEmpty(sLine) || sLine.Equals(""))
        //        {
        //            continue;
        //        }
        //        sLine = sLine.Trim();
        //        switch (sLine.Substring(0, 1))
        //        {
        //            case "#"://注释
        //            case "/"://注释
        //            case "-"://注释
        //                continue;
        //            default:
        //                break;
        //        }
        //        LineList.Add(sLine);
        //    }
        //    objReader.Close();

        //    if (LineList.Count <= 0)
        //    {
        //        errmsg = "代码内容为空!";
        //        return -1;
        //    }

        //    //获取区块key
        //    ArrayList key = new ArrayList();
        //    if (getCommandKey(LineList, out key, out errmsg) < 0)
        //    {
        //        return -1;
        //    }

        //    //获取变量key
        //    ArrayList varkey = new ArrayList();
        //    if (getVarKey(LineList, out varkey, out errmsg) < 0)
        //    {
        //        return -1;
        //    }

        //    //获取区块代码
        //    cmdarraylist = new Dictionary<string, ArrayList>();
        //    varArrayList = new Dictionary<string, ArrayList>();
        //    varNumberList = new Dictionary<string, int>();
        //    foreach (var item in key)
        //    {
        //        ArrayList value = new ArrayList();
        //        cmdarraylist.Add(item.ToString(), spiltCommandList(item.ToString(), LineList));
        //    }

        //    //获取变量明细
        //    varArrayList = new Dictionary<string, ArrayList>();
        //    foreach (var item in varkey)
        //    {
        //        ArrayList value = new ArrayList();
        //        varArrayList.Add(item.ToString(), spiltVarList(item.ToString(), LineList));
        //        //初始化变量下标
        //        AddvarNumber(item.ToString(), varArrayList[item.ToString()]);
        //    }

        //    return 0;
        //}

        ///// <summary>
        ///// 修改变量下标
        ///// </summary>
        //private static void AddvarNumber(string key, ArrayList inlist)
        //{
        //    int result = 0;

        //    if (!varNumberList.ContainsKey(key))
        //    {
        //        varNumberList.Add(key, result);
        //    }
        //    else
        //    {
        //        result = varNumberList[key] + 1;
        //        if (result >= inlist.Count)
        //        {
        //            result = 0;
        //        }
        //        varNumberList[key] = result;
        //    }
        //}

        ///// <summary>
        ///// 初始化变量
        ///// </summary>
        //public static void InitGameValue()
        //{
        //    gamevalue = new Dictionary<string, int>();
        //    gamevalue.Add("m", 100);
        //    gamevalue.Add("M", 400);
        //    gamevalue.Add("h", 100);
        //    gamevalue.Add("H", 100);
        //}

        ///// <summary>
        ///// 获取指定窗口句柄的内存地址
        ///// </summary>
        //public static int ReadProssmemory(IntPtr hWnd, string address)
        //{
        //    byte[] bt = new byte[1024];
        //    int calcID;
        //    int dataAddress;
        //    int readByte;
        //    //由窗体句柄获得进程ID
        //    GetWindowThreadProcessId(hWnd, out calcID);
        //    //由进程ID获得进程句柄
        //    int hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE, false, calcID);
        //    //读取进程指定的内存地址
        //    ReadProcessMemory(hProcess, Convert.ToInt32("004C3EDC", 16), out dataAddress, 2, out readByte);
        //    return dataAddress;
        //}

        ///// <summary>
        ///// 调用sendinput发送windows命令
        ///// </summary>
        //public static void sendinput()
        //{
        //    MouseInput myMinput = new MouseInput();

        //    int ScreenWidth = Screen.PrimaryScreen.WorkingArea.Width;
        //    int ScreenHeight = Screen.PrimaryScreen.WorkingArea.Height;

        //    int dx = 300 * (65335 / ScreenWidth); //x,y为像素坐标。
        //    int dy = 200 * (65335 / ScreenHeight);//ScreenWidth和ScreenHeight，其实是当前显示器的分辨率，获得方法是ScreenWidth=Screen.PrimaryScreen.WorkingArea.Width；

        //    myMinput.dx = dx;
        //    myMinput.dy = dy;
        //    myMinput.Mousedata = 0;
        //    myMinput.dwFlag = MouseEvent_Absolute | MouseEvent_Move | MouseEvent_LeftDown | MouseEvent_LeftUp;
        //    myMinput.time = 0;
        //    Input[] myInput = new Input[1];
        //    myInput[0] = new Input();
        //    myInput[0].type = 0;
        //    myInput[0].mi = myMinput;
        //    UInt32 result = SendInput((uint)myInput.Length, myInput, Marshal.SizeOf(myInput[0].GetType()));
        //}
    }
}
